home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / gamma-bros.swf / scripts / __Packages / classes / enemy / DroidA2.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  13.4 KB  |  464 lines

  1. class classes.enemy.DroidA2
  2. {
  3.    var x;
  4.    var y;
  5.    var moveScript;
  6.    var id;
  7.    var clip;
  8.    var matrixVar;
  9.    var dir;
  10.    var f2;
  11.    var axis;
  12.    var matrixCoords;
  13.    var xDest;
  14.    var yDest;
  15.    var form;
  16.    var advanceMax2;
  17.    var advanceMax;
  18.    var oldDir;
  19.    var xMov = 0;
  20.    var yMov = 0;
  21.    var xmt = 0;
  22.    var ymt = 0;
  23.    var xMovT = 0;
  24.    var yMovT = 0;
  25.    var speedOrig = 8;
  26.    var speed = 8;
  27.    var xDestMet = false;
  28.    var yDestMet = false;
  29.    var c = 0;
  30.    var feelerInfo = [[-400,0,400,40],[0,0,400,40],[0,-400,40,400],[0,0,40,400]];
  31.    var dirArray = ["L","R","U","D"];
  32.    var power = 15;
  33.    var bg = false;
  34.    var Name = "droidA2";
  35.    function DroidA2(px, py, pmoveScript, pbg, pid)
  36.    {
  37.       this.x = px;
  38.       this.y = py;
  39.       this.moveScript = pmoveScript.slice();
  40.       var _loc6_ = pbg.slice();
  41.       this.bg = _loc6_[0];
  42.       this.id = pid;
  43.       _root.d = _root.d + 1;
  44.       this.clip = _root.attachMovie("droidA","droidA2" + this.id + "Clip",_root.d + 50000);
  45.       this.clip._x = this.x;
  46.       this.clip._y = this.y;
  47.       this.speedVar();
  48.       var _loc4_ = new flash.geom.Transform(this.clip);
  49.       if(!this.bg)
  50.       {
  51.          var _loc3_ = _root.randRange(-20,20);
  52.          var _loc5_ = new flash.geom.ColorTransform(1,1,1,1,_loc3_,_loc3_,_loc3_,0);
  53.          _loc4_.colorTransform = _loc5_;
  54.       }
  55.       else
  56.       {
  57.          _loc5_ = new flash.geom.ColorTransform(1,1,1,1,-80,-80,-60,0);
  58.          _loc4_.colorTransform = _loc5_;
  59.          this.clip._xscale = 66;
  60.          this.clip._yscale = 66;
  61.          this.speed *= 0.66;
  62.       }
  63.       this.parseMoveScript();
  64.    }
  65.    function broBehind()
  66.    {
  67.       this.matrixVar = 0;
  68.       this.yMovT = 0;
  69.       if(random(3) == 1)
  70.       {
  71.          var _loc3_ = _root.randRange2(1.2,1.4);
  72.          this.xMovT = this.dir != "L" ? _loc3_ * this.speed : -1 * _loc3_ * this.speed;
  73.          this.clip.body.gotoAndPlay("attack");
  74.          this.clip.body.face.gotoAndPlay("attack");
  75.          this.clip.body.flame.gotoAndPlay("start");
  76.          this.f2 = "attacking";
  77.       }
  78.       else
  79.       {
  80.          this[this.axis + "MovT"] = 0;
  81.          this.axis = random(2) <= 0 ? "x" : "y";
  82.          _loc3_ = _root.randRange2(0.9,1.1);
  83.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * _loc3_ * this.speed : _loc3_ * this.speed;
  84.          this.getDirString();
  85.          this.clip.body.flame.gotoAndPlay("start");
  86.          this.f2 = "wander";
  87.       }
  88.    }
  89.    function speedVar()
  90.    {
  91.       if(random(3) == 1)
  92.       {
  93.          this.speed *= _root.randRange2(0.9999,1.0001);
  94.       }
  95.    }
  96.    function bombed(num)
  97.    {
  98.       this.f2 = "death";
  99.    }
  100.    function parseMoveScript()
  101.    {
  102.       this.dir = this.moveScript[0];
  103.       if(this.dir == "break")
  104.       {
  105.          delete this.moveScript;
  106.          this[this.axis + "MovT"] = 0;
  107.          if(this.matrixCoords[0] == "free")
  108.          {
  109.             this.f2 = "wander";
  110.             this.axis = random(10) <= 4 ? "y" : "x";
  111.             this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  112.             this.speedVar();
  113.             this.getDirString();
  114.          }
  115.          else
  116.          {
  117.             this.xDest = _root.advanceDir != "L" ? this.matrixCoords[0] * 60 : this.matrixCoords[0] * 60 + 320;
  118.             this.yDest = this.matrixCoords[1] * 50 + 10;
  119.             this.axis = Math.abs(this.xDest - this.x) <= Math.abs(this.yDest - this.y) ? "y" : "x";
  120.             this[this.axis + "MovT"] = this[this.axis + "Dest"] <= this[this.axis] ? -1 * this.speed : this.speed;
  121.             this.getDirString();
  122.             this.speedVar();
  123.             this.f2 = "gotoMatrix";
  124.          }
  125.       }
  126.       else
  127.       {
  128.          this[this.axis + "MovT"] = 0;
  129.          this.f2 = "gotoXYDest";
  130.          this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  131.          this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  132.          this.speedVar();
  133.          if(this.dir == "L" || this.dir == "U")
  134.          {
  135.             this[this.axis + "Dest"] = this[this.axis] - this.moveScript[1];
  136.          }
  137.          else
  138.          {
  139.             this[this.axis + "Dest"] = this[this.axis] + this.moveScript[1];
  140.          }
  141.          this.moveScript.splice(0,2);
  142.       }
  143.    }
  144.    function gotoXYDest()
  145.    {
  146.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  147.       {
  148.          if(this.axis == "x")
  149.          {
  150.             this.x = this.xDest;
  151.          }
  152.          else
  153.          {
  154.             this.y = this.yDest;
  155.          }
  156.          this.parseMoveScript();
  157.       }
  158.    }
  159.    function gotoMatrix()
  160.    {
  161.       if(Math.abs(this[this.axis + "Dest"] - this[this.axis]) < this.speed + 1)
  162.       {
  163.          if(this.axis == "x")
  164.          {
  165.             this.x = this.xDest;
  166.          }
  167.          else
  168.          {
  169.             this.y = this.yDest;
  170.          }
  171.          this[this.axis + "MovT"] = 0;
  172.          this.axis = this.axis != "x" ? "x" : "y";
  173.          this[this.axis + "MovT"] = this[this.axis + "Dest"] <= this[this.axis] ? -1 * this.speed : this.speed;
  174.          this.getDirString();
  175.          this.speed = this.speedOrig;
  176.       }
  177.       if(Math.abs(this.x - this.xDest) < this.speed + 1 && Math.abs(this.y - this.yDest) < this.speed + 1)
  178.       {
  179.          this.x = this.clip._x = this.xDest;
  180.          this.y = this.clip._y = this.yDest;
  181.          this.xMovT = this.xMov = 0;
  182.          this.yMovT = this.yMov = 0;
  183.          this.matrixVar = 2;
  184.          this.dir = _root.advanceDir;
  185.          this.clip.body.flame.gotoAndPlay("still");
  186.          _root.matrixNum = _root.matrixNum + 1;
  187.          if(_root.matrixNum >= _root.matrixSize)
  188.          {
  189.             _root.matrixComplete = true;
  190.          }
  191.          _root["formB" + this.form[0]] = "matrixed";
  192.          this.f2 = "wait";
  193.       }
  194.    }
  195.    function getDirString()
  196.    {
  197.       if(this.xMovT < -1)
  198.       {
  199.          this.dir = "L";
  200.       }
  201.       else if(this.xMovT > 1)
  202.       {
  203.          this.dir = "R";
  204.       }
  205.       else if(this.yMovT > 1)
  206.       {
  207.          this.dir = "D";
  208.       }
  209.       else if(this.yMovT < -1)
  210.       {
  211.          this.dir = "U";
  212.       }
  213.    }
  214.    function wait()
  215.    {
  216.       if(random(1000) >= 998 && _root.matrixComplete)
  217.       {
  218.          this.dir = this.findDir();
  219.          if(this.dir == _root.advanceDir)
  220.          {
  221.             this.xMovT = _root.advanceDir != "L" ? 1.3 * this.speed : -1.3 * this.speed;
  222.             this.clip.body.gotoAndPlay("attack");
  223.             this.clip.body.face.gotoAndPlay("attack");
  224.             this.clip.body.flame.gotoAndPlay("start");
  225.             this.f2 = "attacking";
  226.             this.matrixVar = 0;
  227.          }
  228.          else if(this.dir == "U" || this.dir == "D")
  229.          {
  230.             this.axis = !(this.dir == "L" || this.dir == "R") ? "y" : "x";
  231.             this[this.axis + "MovT"] = !(this.dir == "L" || this.dir == "U") ? this.speed : -1 * this.speed;
  232.             this.matrixVar = 0;
  233.             this.c = 0;
  234.             this.f2 = "leavingMatrix";
  235.             this.clip.body.flame.gotoAndPlay("start");
  236.          }
  237.          else
  238.          {
  239.             this.dir = _root.advanceDir;
  240.          }
  241.       }
  242.    }
  243.    function leavingMatrix()
  244.    {
  245.       this.c = this.c + 1;
  246.       if(this.c > this.advanceMax2)
  247.       {
  248.          this.c = 0;
  249.          this.dir = this.findDir();
  250.          if(this.dir == _root.advanceDir)
  251.          {
  252.             this.yMovT = 0;
  253.             this.xMovT = _root.advanceDir != "L" ? 1.3 * this.speed : -1.3 * this.speed;
  254.             this.clip.body.gotoAndPlay("attack");
  255.             this.clip.body.face.gotoAndPlay("attack");
  256.             this.f2 = "attacking";
  257.          }
  258.       }
  259.    }
  260.    function findDir()
  261.    {
  262.       _root.d = _root.d + 1;
  263.       _root.attachMovie("feeler","feelerClip",_root.d);
  264.       var _loc7_ = [];
  265.       var _loc9_ = 0;
  266.       var _loc11_ = this.dirArray.length;
  267.       while(_loc9_ < _loc11_)
  268.       {
  269.          _root.feelerClip._x = this.x + this.feelerInfo[_loc9_][0];
  270.          _root.feelerClip._y = this.y + this.feelerInfo[_loc9_][1];
  271.          _root.feelerClip._width = this.feelerInfo[_loc9_][2];
  272.          _root.feelerClip._height = this.feelerInfo[_loc9_][3];
  273.          var _loc3_ = 0;
  274.          var _loc8_ = _root.chars.length;
  275.          var _loc6_ = false;
  276.          while(_loc3_ < _loc8_)
  277.          {
  278.             var _loc5_ = _root.chars[_loc3_] + "Clip";
  279.             if(_root.feelerClip.hitTest(_root[_loc5_]))
  280.             {
  281.                var _loc4_ = _root.chars[_loc3_];
  282.                if(_root[_loc4_].matrixVar == 2 && _loc4_ != this.Name + this.id)
  283.                {
  284.                   _loc6_ = true;
  285.                   break;
  286.                }
  287.             }
  288.             _loc3_ = _loc3_ + 1;
  289.          }
  290.          if(!_loc6_)
  291.          {
  292.             var _loc10_ = _root.advanceDir != "L" ? "L" : "R";
  293.             if(this.dirArray[_loc9_] != _loc10_)
  294.             {
  295.                _loc7_.push(this.dirArray[_loc9_]);
  296.             }
  297.          }
  298.          _loc9_ = _loc9_ + 1;
  299.       }
  300.       _loc9_ = 0;
  301.       _loc11_ = _loc7_.length;
  302.       if(_loc9_ < _loc11_)
  303.       {
  304.          if(_loc7_[_loc9_] == _root.advanceDir)
  305.          {
  306.             return _root.advanceDir;
  307.          }
  308.          return _loc7_[random(_loc7_.length)];
  309.       }
  310.    }
  311.    function attacking()
  312.    {
  313.    }
  314.    function death()
  315.    {
  316.       if(this.matrixVar == 1)
  317.       {
  318.          _root.matrixNum = _root.matrixNum + 1;
  319.          if(_root.matrixNum >= _root.matrixSize)
  320.          {
  321.             _root.matrixComplete = true;
  322.          }
  323.       }
  324.       _root.powerUp(this.x,this.y,96);
  325.       var _loc3_ = 0;
  326.       var _loc4_ = _root["form" + this.form[0]].length;
  327.       while(_loc3_ < _loc4_)
  328.       {
  329.          if(_root["form" + this.form[0]][_loc3_] == "droidA2" + this.id)
  330.          {
  331.             _root["form" + this.form[0]].splice(_loc3_,1);
  332.             if(_root["form" + this.form[0]].length == 0)
  333.             {
  334.                delete _root["form" + this.form[0]];
  335.                if(_root["formB" + this.form[0]] == "matrixed")
  336.                {
  337.                   _root.createPowerUp([this.x,this.y,"coin1"]);
  338.                }
  339.                else
  340.                {
  341.                   _root.createPowerUp([this.x,this.y,"coin1"]);
  342.                }
  343.                delete _root["formB" + this.form[0]];
  344.             }
  345.             break;
  346.          }
  347.          _loc3_ = _loc3_ + 1;
  348.       }
  349.       _root.createExploA([this.x + this.clip._width / 2,this.y + this.clip._height / 2,_root.randRange(80,130),_root.randRange(75,100)]);
  350.       _loc3_ = 0;
  351.       _loc4_ = random(3);
  352.       while(_loc3_ < _loc4_)
  353.       {
  354.          _root.createShrapnel([this.x + this.clip._width / 2,this.y + this.clip._height / 2,"droidA2"]);
  355.          _loc3_ = _loc3_ + 1;
  356.       }
  357.       _root.createDroidA2Soul([this.x + this.clip._width / 2,this.y + this.clip._height / 2]);
  358.       _root.removeChar("droidA2" + this.id);
  359.       this.f2 = "";
  360.    }
  361.    function advance()
  362.    {
  363.       this.dir = _root.advanceDir;
  364.       this.clip.body.flame.gotoAndPlay("advance");
  365.       this.xMovT = _root.advanceDir != "L" ? 1 * (this.speed / 2) : -1 * (this.speed / 2);
  366.       this.f2 = "advancing";
  367.    }
  368.    function advancing()
  369.    {
  370.       this.c = this.c + 1;
  371.       if(this.c > this.advanceMax)
  372.       {
  373.          this.xMovT = 0;
  374.          this.c = 0;
  375.          this.f2 = "wait";
  376.          _root.d = _root.d + 1;
  377.          _root.attachMovie("sight","sightClip",_root.d);
  378.          _root.sightClip.gotoAndStop("hindSight");
  379.          _root.sightClip._x = this.x;
  380.          _root.sightClip._y = this.y;
  381.          if(_root.advanceDir == "L")
  382.          {
  383.             _root.sightClip._rotation = 180;
  384.          }
  385.          if(_root.sightClip.hitTest(_root[_root.char].x,_root[_root.char].y,true))
  386.          {
  387.             _root.broBehind();
  388.          }
  389.          removeMovieClip(_root.sightClip);
  390.       }
  391.    }
  392.    function wander()
  393.    {
  394.       if(random(100) > 98)
  395.       {
  396.          this[this.axis + "MovT"] = 0;
  397.          this.axis = this.axis != "x" ? "x" : "y";
  398.          this[this.axis + "MovT"] = random(2) <= 0 ? -1 * this.speed : this.speed;
  399.          this.getDirString();
  400.       }
  401.    }
  402.    function death2()
  403.    {
  404.       _root.removeChar("droidA2" + this.id);
  405.       this.f2 = "";
  406.    }
  407.    function main()
  408.    {
  409.       this[this.f2]();
  410.       if(this.oldDir != this.dir)
  411.       {
  412.          this.clip.gotoAndStop("fly" + this.dir);
  413.       }
  414.       this.oldDir = this.dir;
  415.       if(this.x > 1050 || this.x < -50 || this.y < -50 || this.y > 650)
  416.       {
  417.          delete _root["form" + this.form[0]];
  418.          delete _root["formB" + this.form[0]];
  419.          this.f2 = "death2";
  420.       }
  421.       if(this.xMovT < this.xMov)
  422.       {
  423.          this.xMov -= 1;
  424.       }
  425.       else if(this.xMovT > this.xMov)
  426.       {
  427.          this.xMov += 1;
  428.       }
  429.       else
  430.       {
  431.          this.xMov = this.xMovT;
  432.       }
  433.       if(this.yMovT < this.yMov)
  434.       {
  435.          this.yMov -= 1;
  436.       }
  437.       else if(this.yMovT > this.yMov)
  438.       {
  439.          this.yMov += 1;
  440.       }
  441.       else
  442.       {
  443.          this.yMov = this.yMovT;
  444.       }
  445.       this.xmt = this.xMov;
  446.       this.ymt = this.yMov;
  447.       if(random(10) == 1)
  448.       {
  449.          if(this.axis == "y")
  450.          {
  451.             this.xmt += _root.randRange2(-1,1);
  452.          }
  453.          else
  454.          {
  455.             this.ymt += _root.randRange2(-1,1);
  456.          }
  457.       }
  458.       this.x += this.xmt;
  459.       this.y += this.ymt;
  460.       this.clip._x = this.x;
  461.       this.clip._y = this.y;
  462.    }
  463. }
  464.